﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using System.Configuration;

class Customers
{
    public string ContactName { get; set; }
    public string City { get; set; }
    public string PostalCode { get; set; }
    public string Country { get; set; }
    public string Phone { get; set; }
    public string Fax { get; set; }
    public string PageCount { get; set; }
}
public partial class CS : System.Web.UI.Page
{
  static  DataSet Get(int page)
    {
        DataSet set = new DataSet();
        DataTable table = new DataTable("News");
        table.Columns.Add("ContactName");
        table.Columns.Add("City");
        table.Columns.Add("PostalCode");
        table.Columns.Add("Country");
        table.Columns.Add("Phone");
        table.Columns.Add("Fax");
        table.Columns.Add("PageCount", typeof(int));
        for (int i = 0; i < 10; i++)
        {
            DataRow row = table.NewRow();
            row["ContactName"] = "1";
            row["City"] = "d";
            row["PageCount"] = 100;
            table.Rows.Add(row);
        }
        
        set.Tables.Add(table);
        return set;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            rptCustomers.DataSource = Get(1);
            rptCustomers.DataBind();
        }
    }
    public static DataSet GetCustomersData(int pageIndex)
    {
        string query = "[GetCustomersPageWise]";
        SqlCommand cmd = new SqlCommand(query);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
        cmd.Parameters.AddWithValue("@PageSize", 10);
        cmd.Parameters.Add("@PageCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
        return GetData(cmd);
    }
    private static DataSet GetData(SqlCommand cmd)
    {
        string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(strConnString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataSet ds = new DataSet())
                {
                    sda.Fill(ds, "Customers");
                    DataTable dt = new DataTable("PageCount");
                    dt.Columns.Add("PageCount");
                    dt.Rows.Add();
                    dt.Rows[0][0] = cmd.Parameters["@PageCount"].Value;
                    ds.Tables.Add(dt);
                    return ds;
                }
            }
        }
    }

    [WebMethod]
    public static string GetCustomers(int pageIndex)
    {
        return Get(pageIndex).GetXml();
    }

}